﻿using SD.IOC.Core.Mediators;
using SD.Toolkits.Excel;
using SlamDunk.MES.DataDrive.Bussiness.Models.ConfigurationContext;
using SlamDunk.MES.DataDrive.Bussiness.Models.FoundationContext;
using SlamDunk.MES.DataDrive.Bussiness.Models.ResourceContext;
using SlamDunk.MES.DataDrive.Common;
using SlamDunk.MES.DataDrive.Common.Attributes;
using SlamDunk.MES.IAppService.DTOs.Inputs;
using SlamDunk.MES.IAppService.DTOs.Outputs.ConfigurationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.FoundationContext;
using SlamDunk.MES.IAppService.DTOs.Outputs.ResourceContext;
using SlamDunk.MES.IAppService.Interfaces;
using SlamDunk.ValueObjects.Enums;
using System;
using System.Collections.Generic;
using System.Linq;

namespace SlamDunk.MES.DataDrive.Bussiness.Importers
{
    /// <summary>
    /// 导入基础数据
    /// </summary>
    [DataTag(12, "基础数据", "MES基础数据", DataDriveConfig.RealgoalName, DataDriveConfig.RealgoalConnectionStrings)]
    public class ImportFoundation
    {
        #region # 导入终端 —— void ImportTerminals()
        /// <summary>
        /// 导入终端
        /// </summary>
        [DataTag("导入终端")]
        public void ImportTerminals()
        {
            Terminal[] terminals = ExcelReader.ReadFile<Terminal>(SystemConfig.InitalForBaseDataPath, "终端");
            IConfigurationContract configurationContract = ResolveMediator.Resolve<IConfigurationContract>();

            foreach (Terminal terminal in terminals)
            {
                configurationContract.CreateTerminal(terminal.终端编号, terminal.终端名称, terminal.描述);
            }
        }
        #endregion

        #region # 导入硬件 —— void ImportHardwares()
        /// <summary>
        /// 导入硬件
        /// </summary>
        [DataTag("导入硬件")]
        public void ImportHardwares()
        {
            IConfigurationContract configurationContract = ResolveMediator.Resolve<IConfigurationContract>();
            Hardware[] hardwares = ExcelReader.ReadFile<Hardware>(SystemConfig.InitalForBaseDataPath, "硬件");
            HardwareConfig[] hardwareConfigs = ExcelReader.ReadFile<HardwareConfig>(SystemConfig.InitalForBaseDataPath, "硬件配置");

            if (ImportCacheData.TerminalInfos == null)
            {
                List<TerminalInfo> terminalInfos = configurationContract.GetTerminalsByPage(string.Empty, 1, int.MaxValue).Datas.ToList();
                ImportCacheData.TerminalInfos = terminalInfos;
            }

            foreach (Hardware hardware in hardwares)
            {
                hardware.ConverterValue();
                configurationContract.CreateHardware(hardware.硬件编号, hardware.硬件名称, hardware.HardwareType, hardware.型号, hardware.备注);
            }
            //获取硬件集合
            List<HardwareInfo> hardwareInfos = configurationContract.GetHardwaresByPage(null, null, null, 1, int.MaxValue).Datas.ToList();

            foreach (HardwareInfo hardwareInfo in hardwareInfos)
            {
                //配置网口通讯
                foreach (HardwareConfig hardwareConfig in hardwareConfigs.Where(x => x.Is网络通讯 && x.硬件编号 == hardwareInfo.Number))
                {
                    Guid terminalId = ImportCacheData.TerminalInfos.First(x => x.Number == hardwareConfig.终端编号).Id;
                    configurationContract.ConfigureHardwareNetworkMode(hardwareInfo.Id, terminalId, hardwareConfig.IP地址, hardwareConfig.端口号);
                }
                //配置串口通讯
                foreach (var hardwareConfig in hardwareConfigs.Where(x => !x.Is网络通讯 && x.硬件编号 == hardwareInfo.Number))
                {
                    Guid terminalId = ImportCacheData.TerminalInfos.First(x => x.Number == hardwareConfig.终端编号).Id;
                    configurationContract.ConfigureHardwareSerialPortMode(hardwareInfo.Id, terminalId, hardwareConfig.Com口号, hardwareConfig.波特率, (StopBits)hardwareConfig.停止位, (Parity)hardwareConfig.校验位, hardwareConfig.数据位, false, false);
                }
            }
        }
        #endregion

        #region # 导入工厂模型 —— void ImportFacilities()
        /// <summary>
        /// 导入工厂模型
        /// </summary>
        [DataTag("导入工厂模型")]
        public void ImportFacilities()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            Facility[] facilities = ExcelReader.ReadFile<Facility>(SystemConfig.InitalForBaseDataPath, "工厂模型");

            foreach (IGrouping<string, Facility> facilityGroup in facilities.GroupBy(x => x.上级节点编号))
            {
                FacilityInfo facilityParentInfo = foundationContract.GetFacilities(facilityGroup.Key, null, null, null).FirstOrDefault(x => x.Number == facilityGroup.Key);
                Guid? facilityParentId = facilityParentInfo?.Id;

                foreach (Facility facility in facilityGroup)
                {
                    facility.ConverterValue();
                    foundationContract.CreateFacility(facilityParentId, facility.工厂模型编号, facility.工厂模型名称, facility.FacilityLevel, facility.FacilityType, facility.描述);
                }
            }
        }
        #endregion

        #region # 导入工位 —— void ImportWorkStations()
        /// <summary>
        /// 导入操作位置
        /// </summary>
        [DataTag("导入工位")]
        public void ImportWorkStations()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            Workstation[] workstations = ExcelReader.ReadFile<Workstation>(SystemConfig.InitalForBaseDataPath, "工位");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Workstation workstation in workstations)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == workstation.工厂模型编号)?.Id;
                foundationContract.CreateWorkStation(workstation.工位编号, workstation.工位名称, facilityId, workstation.描述);
            }
        }
        #endregion

        #region # 导入计量单位组 —— void ImportMeasureUnitGroup()
        /// <summary>
        /// 导入计量单位组
        /// </summary>
        [DataTag("导入计量单位组")]
        public void ImportMeasureUnitGroup()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            MeasureUnitGroup[] measureUnitGroups = ExcelReader.ReadFile<MeasureUnitGroup>(SystemConfig.InitalForBaseDataPath, "计量单位组");
            MeasureUnit[] measureUnits = ExcelReader.ReadFile<MeasureUnit>(SystemConfig.InitalForBaseDataPath, "计量单位");
            IGrouping<string, MeasureUnit>[] unitsGroups = measureUnits.GroupBy(x => x.计量单位组编号).ToArray();

            foreach (MeasureUnitGroup measureUnitGroup in measureUnitGroups)
            {
                IGrouping<string, MeasureUnit> units = unitsGroups.Single(x => x.Key == measureUnitGroup.计量单位组编号);
                IEnumerable<MeasureUnitParam> unitParams =
                    from unit in units
                    select new MeasureUnitParam
                    {
                        unitNo = unit.计量单位编号,
                        unitName = unit.计量单位名称,
                        isMaster = unit.是否主计量单位,
                        masterCoefficient = unit.转换系数,
                        sort = unit.排序,
                        description = unit.描述
                    };

                foundationContract.CreateMeasureUnitGroup(measureUnitGroup.计量单位组编号, measureUnitGroup.计量单位组名称, measureUnitGroup.计量单位组描述, unitParams);
            }
        }
        #endregion

        #region # 导入人员类 —— void ImportPersonClasses()
        /// <summary>
        /// 导入人员类
        /// </summary>
        [DataTag("导入人员类")]
        public void ImportPersonClasses()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            PersonClass[] personClasses = ExcelReader.ReadFile<PersonClass>(SystemConfig.InitalForBaseDataPath, "人员类");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (PersonClass personClass in personClasses)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == personClass.工厂模型编号)?.Id;

                IEnumerable<PersonClassInfo> personClassInfo = resourceContract.GetPersonClasses(null, null, null);
                Guid? parentId = personClassInfo.SingleOrDefault(x => x.Number == personClass.上级节点编号)?.Id;
                personClass.上级节点Id = parentId;
                resourceContract.CreatePersonClass(personClass.上级节点Id, personClass.人员类编号, personClass.人员类名称, facilityId, personClass.描述);
            }
        }
        #endregion

        #region # 导入人员 —— void ImportPersons()
        /// <summary>
        /// 导入人员
        /// </summary>
        [DataTag("导入人员")]
        public void ImportPersons()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Person[] persons = ExcelReader.ReadFile<Person>(SystemConfig.InitalForBaseDataPath, "人员");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Person person in persons)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == person.工厂模型编号)?.Id;
                resourceContract.CreatePerson(person.人员编号, person.人员姓名, facilityId, person.描述);
            }
        }
        #endregion

        #region # 关联人员到人员类 —— void RelatePersonsToClasses()
        /// <summary>
        /// 关联人员到人员类
        /// </summary>
        [DataTag("关联人员到人员类")]
        public void RelatePersonsToClasses()
        {
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Person[] persons = ExcelReader.ReadFile<Person>(SystemConfig.InitalForBaseDataPath, "人员");

            IEnumerable<PersonInfo> personInfos = resourceContract.GetPersonsByPage(null, null, null, 1, int.MaxValue).Datas;
            IList<PersonClassInfo> personClassInfos = resourceContract.GetPersonClasses(null, null, null).ToList();

            foreach (PersonInfo personInfo in personInfos)
            {
                string personClassNo = persons.Single(x => x.人员编号 == personInfo.Number).人员类编号;
                if (personClassNo == null)
                {
                    continue;
                }

                IEnumerable<Guid> personClassIds = personClassInfos.Where(x => personClassNo.Split(',').Any(y => y == x.Number)).Select(x => x.Id);
                resourceContract.RelatePersonToClasses(personInfo.Id, personClassIds);
            }
        }
        #endregion

        #region # 导入班组 —— void ImportTeams()
        /// <summary>
        /// 导入班组
        /// </summary>
        [DataTag("导入班组")]
        public void ImportTeams()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Team[] teams = ExcelReader.ReadFile<Team>(SystemConfig.InitalForBaseDataPath, "班组");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            if (ImportCacheData.PersonInfos == null)
            {
                ImportCacheData.PersonInfos = resourceContract.GetPersonsByPage(null, null, null, 1, int.MaxValue).Datas.ToList();
            }
            foreach (Team team in teams)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == team.工厂模型编号)?.Id;

                string[] personNos = team.班组成员.Split(',');
                IEnumerable<TeamMemberParam> teamMemberParams =
                    from personNo in personNos
                    let personInfo = ImportCacheData.PersonInfos.Single(x => x.Number == personNo)
                    select new TeamMemberParam
                    {
                        personId = personInfo.Id
                    };

                resourceContract.CreateTeam(team.班组编号, team.班组名称, facilityId, team.描述, teamMemberParams);
            }
        }
        #endregion

        #region # 导入设备类 —— void ImportEquipmentClasses()
        /// <summary>
        /// 导入设备类
        /// </summary>
        [DataTag("导入设备类")]
        public void ImportEquipmentClasses()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            EquipmentClass[] equipmentClasses = ExcelReader.ReadFile<EquipmentClass>(SystemConfig.InitalForBaseDataPath, "设备类");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (EquipmentClass equipmentClass in equipmentClasses)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == equipmentClass.工厂模型编号)?.Id;

                EquipmentClassInfo equipmentClassInfo = resourceContract.GetEquipmentClasses(null, null, null).SingleOrDefault(x => x.Number == equipmentClass.上级节点编号);
                Guid? parentId = equipmentClassInfo?.Id;
                equipmentClass.上级节点Id = parentId;
                resourceContract.CreateEquipmentClass(equipmentClass.上级节点Id, equipmentClass.设备类编号, equipmentClass.设备类名称, facilityId, equipmentClass.描述);
            }
        }
        #endregion

        #region # 导入设备 —— void ImportEquipments()
        /// <summary>
        /// 导入设备
        /// </summary>
        [DataTag("导入设备")]
        public void ImportEquipments()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Equipment[] equipments = ExcelReader.ReadFile<Equipment>(SystemConfig.InitalForBaseDataPath, "设备");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Equipment equipment in equipments)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == equipment.工厂模型编号)?.Id;
                resourceContract.CreateEquipment(equipment.设备编号, equipment.设备名称, facilityId, equipment.描述);
            }
        }
        #endregion

        #region # 关联设备到设备类 —— void RelateEquipmentsToClasses()
        /// <summary>
        /// 关联设备到设备类
        /// </summary>
        [DataTag("关联设备到设备类")]
        public void RelateEquipmentsToClasses()
        {
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Equipment[] equipments = ExcelReader.ReadFile<Equipment>(SystemConfig.InitalForBaseDataPath, "设备");

            IEnumerable<EquipmentInfo> equipmentInfos = resourceContract.GetEquipmentsByPage(null, null, null, 1, int.MaxValue).Datas;
            IList<EquipmentClassInfo> equipmentClassInfos = resourceContract.GetEquipmentClasses(null, null, null).ToList();

            foreach (EquipmentInfo equipmentInfo in equipmentInfos)
            {
                string equipmentClassNo = equipments.Single(x => x.设备编号 == equipmentInfo.Number).设备类编号;
                if (equipmentClassNo == null)
                {
                    continue;
                }

                IEnumerable<Guid> equipmentClassIds = equipmentClassInfos.Where(x => equipmentClassNo.Split(',').Any(y => y == x.Number)).Select(x => x.Id);
                resourceContract.RelateEquipmentToClasses(equipmentInfo.Id, equipmentClassIds);
            }
        }
        #endregion

        #region # 导入物料类 —— void ImportMaterialClasses()
        /// <summary>
        /// 导入物料类
        /// </summary>
        [DataTag("导入物料类")]
        public void ImportMaterialClasses()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            MaterialClass[] materialClasses = ExcelReader.ReadFile<MaterialClass>(SystemConfig.InitalForBaseDataPath, "物料类");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (MaterialClass materialClass in materialClasses)
            {
                materialClass.ConverterValue();
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == materialClass.工厂模型编号)?.Id;

                MaterialClassInfo classInfo = resourceContract.GetMaterialClasses(null, null, null, null).SingleOrDefault(x => x.Number == materialClass.上级节点编号);
                Guid? parentId = classInfo?.Id;
                materialClass.上级节点Id = parentId;
                resourceContract.CreateMaterialClass(materialClass.上级节点Id, materialClass.物料类编号, materialClass.物料类名称, facilityId, materialClass.MaterialSourceType, materialClass.描述);
            }
        }
        #endregion

        #region # 导入物料定义 —— void ImportMaterials()
        /// <summary>
        /// 导入物料定义
        /// </summary>
        [DataTag("导入物料定义")]
        public void ImportMaterials()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Material[] materials = ExcelReader.ReadFile<Material>(SystemConfig.InitalForBaseDataPath, "物料定义");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Material material in materials)
            {
                material.ConverterValue();
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == material.工厂模型编号)?.Id;

                resourceContract.CreateMaterial(material.物料定义编号, material.物料定义名称, material.ERP编号, material.基准单位编号, material.规格, TimeSpan.FromDays(material.保质期), material.MaterialSourceType, material.是否按批次管理, facilityId, material.数据来源, material.描述);
            }
        }

        #endregion

        #region # 导入物料包装 —— void ImportMaterialPacks()
        /// <summary>
        /// 导入物料包装
        /// </summary>
        [DataTag("导入物料包装")]
        public void ImportMaterialPacks()
        {
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            MaterialPack[] materialMainPacks = ExcelReader.ReadFile<MaterialPack>(SystemConfig.InitalForBaseDataPath, "物料包装");

            if (ImportCacheData.MaterialInfos == null)
            {
                ImportCacheData.MaterialInfos = resourceContract.GetMaterialsByPage(null, null, null, null, null, null, 1, int.MaxValue).Datas.ToList();
            }
            foreach (MaterialPack materialPack in materialMainPacks)
            {
                MaterialInfo materialInfo = ImportCacheData.MaterialInfos.First(x => x.Number == materialPack.物料定义编号);
                MaterialPackParam materialPackParam = new MaterialPackParam()
                {
                    maxPack = materialPack.外包装,
                    maxPackCoefficient = string.IsNullOrWhiteSpace(materialPack.外包装系数)
                        ? (int?)null
                        : int.Parse(materialPack.外包装系数),
                    minPack = materialPack.内包装,
                    minPackCoefficient = materialPack.内包装系数,
                };

                resourceContract.SetMaterialPack(materialInfo.Id, materialPackParam);
            }
        }
        #endregion

        #region # 导入物料条码设置 —— void ImportMaterialBarcodeSetting()
        /// <summary>
        /// 导入物料条码设置
        /// </summary>
        [DataTag("导入物料条码设置")]
        public void ImportMaterialBarcodeSetting()
        {
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            MaterialBarcodeSetting[] materialBacodeSettings = ExcelReader.ReadFile<MaterialBarcodeSetting>(SystemConfig.InitalForBaseDataPath, "物料条码设置");

            if (ImportCacheData.MaterialInfos == null)
            {
                ImportCacheData.MaterialInfos = resourceContract.GetMaterialsByPage(null, null, null, null, null, null, 1, int.MaxValue).Datas.ToList();
            }
            foreach (MaterialBarcodeSetting materialBacodeSetting in materialBacodeSettings)
            {
                materialBacodeSetting.ConverterValue();
                MaterialInfo materialInfo = ImportCacheData.MaterialInfos.First(x => x.Number == materialBacodeSetting.物料定义编号);
                MaterialBarcodeSettingParam materialBarcodeSettingParam = new MaterialBarcodeSettingParam()
                {
                    needPrintBarcode = materialBacodeSetting.是否打印条码,
                    barcodeMode = materialBacodeSetting.BarcodeMode,
                    barcodeUnit = materialBacodeSetting.条码单位
                };

                resourceContract.SetMaterialBarcodeSetting(materialInfo.Id, materialBarcodeSettingParam);
            }
        }
        #endregion

        #region # 关联物料定义到物料类 —— void RelateMaterialsToClasses()
        /// <summary>
        /// 关联物料定义到物料类
        /// </summary>
        [DataTag("关联物料定义到物料类")]
        public void RelateMaterialsToClasses()
        {
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Material[] materials = ExcelReader.ReadFile<Material>(SystemConfig.InitalForBaseDataPath, "物料定义");

            IEnumerable<MaterialInfo> materialInfos = resourceContract.GetMaterialsByPage(null, null, null, null, null, null, 1, int.MaxValue).Datas;
            IList<MaterialClassInfo> materialClassInfos = resourceContract.GetMaterialClasses(null, null, null, null).ToList();

            foreach (MaterialInfo materialInfo in materialInfos)
            {
                string materialClassNo = materials.Single(x => x.物料定义编号 == materialInfo.Number).物料类编号;
                if (materialClassNo == null)
                {
                    continue;
                }

                IEnumerable<Guid> materialClassIds = materialClassInfos.Where(x => materialClassNo.Split(',').Any(y => y == x.Number)).Select(x => x.Id);
                resourceContract.RelateMaterialToClasses(materialInfo.Id, materialClassIds);
            }
        }
        #endregion

        #region # 导入企业 —— void ImportEnterprises()
        /// <summary>
        /// 导入企业
        /// </summary>
        [DataTag("导入企业")]
        public void ImportEnterprises()
        {
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            IResourceContract resourceContract = ResolveMediator.Resolve<IResourceContract>();
            Enterprise[] enterprises = ExcelReader.ReadFile<Enterprise>(SystemConfig.InitalForBaseDataPath, "企业");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Enterprise enterprise in enterprises)
            {
                enterprise.ConverterValue();
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == enterprise.工厂模型编号)?.Id;

                resourceContract.CreateEnterprise(enterprise.企业编号, enterprise.企业名称, enterprise.EnterpriseType, facilityId, enterprise.联系地址, enterprise.联系电话, enterprise.联系人, enterprise.传真, enterprise.法人, enterprise.营业执照编号, enterprise.描述);
            }
        }
        #endregion

        #region # 导入工作通知 —— void ImportNotifications()
        /// <summary>
        /// 导入工作通知
        /// </summary>
        [DataTag("导入工作通知")]
        public void ImportNotifications()
        {
            IConfigurationContract configurationContract = ResolveMediator.Resolve<IConfigurationContract>();
            IFoundationContract foundationContract = ResolveMediator.Resolve<IFoundationContract>();
            Notification[] notifications = ExcelReader.ReadFile<Notification>(SystemConfig.InitalForBaseDataPath, "工作通知");

            if (ImportCacheData.FacilityInfos == null)
            {
                ImportCacheData.FacilityInfos = foundationContract.GetFacilities(null, null, null, null).ToList();
            }
            foreach (Notification notification in notifications)
            {
                Guid? facilityId = ImportCacheData.FacilityInfos.FirstOrDefault(x => x.Number == notification.工厂模型编号)?.Id;

                configurationContract.CreateNotification(notification.标题, notification.内容, notification.下发日期, facilityId, notification.优先级, notification.描述);
            }
        }
        #endregion
    }
}
